﻿package mortal.game.proxy
{
    import Framework.Util.*;
    import Message.Game.*;
    import Message.Public.*;
    import com.gengine.core.frame.*;
    import com.gengine.debug.*;
    import flash.geom.*;
    import flash.utils.*;
    import mortal.common.error.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.net.rmi.*;
    import mortal.game.scene3D.ai.*;
    import mortal.game.scene3D.map3D.util.*;
    import mortal.game.view.task.*;
    import mortal.game.view.task.guild.*;
    import mortal.mvc.core.*;

    public class TaskProxy extends Proxy
    {
        public static var clickShareTime:int = -1;

        public function TaskProxy()
        {
            return;
        }// end function

        public function getTask(param1:int, param2:int, param3:int = 0) : void
        {
            if (cache.task.getTaskByCode(param2, true) != null)
            {
                return;
            }
            TaskCache.endTaskTime = FrameManager.flashFrame.getTime();
            GameRMI.instance.iTask.getTask_async(new AMI_ITask_getTask(this.getTaskSucess, this.submitTaskFail, param2), param1, param2, param3);
            return;
        }// end function

        private function getTaskSucess(param1:AMI_ITask_getTask) : void
        {
            NetDispatcher.dispatchCmd(ServerCommand.TaskGetSucess, param1.userObject);
            this.submitTaskSucess();
            return;
        }// end function

        public function talkToNpc(param1:int, param2:int, param3:int = 0) : void
        {
            GameRMI.instance.iTask.talkToNpc_async(new AMI_ITask_talkToNpc(this.submitTaskSucess, this.submitTaskFail), param2, param1, param3);
            TaskCache.endTaskTime = FrameManager.flashFrame.getTime();
            return;
        }// end function

        public function endTask(param1:int, param2:int, param3:int = 0) : void
        {
            GameRMI.instance.iTask.endTask_async(new AMI_ITask_endTask(this.finishTaskSuccess, this.submitTaskFail, param2), param1, param2, param3);
            TaskCache.endTaskTime = FrameManager.flashFrame.getTime();
            return;
        }// end function

        private function finishTaskSuccess(param1:AMI_ITask_endTask) : void
        {
            NetDispatcher.dispatchCmd(ServerCommand.TaskSubmitSuccess, param1.userObject);
            this.submitTaskSucess();
            return;
        }// end function

        private function submitTaskSucess(param1 = null) : void
        {
            Log.error("任务Responds一共用了时间=" + (getTimer() - TaskCache.endTaskTime));
            return;
        }// end function

        private function submitTaskFail(param1:Exception) : void
        {
            var _loc_2:* = param1.message;
            if (!_loc_2)
            {
                _loc_2 = ErrorCode.getErrorStringByCode(param1.code);
            }
            MsgManager.showRollTipsMsg(_loc_2);
            Log.error("任务Responds一共用了时间=" + (getTimer() - TaskCache.endTaskTime));
            return;
        }// end function

        public function endGuide(param1:int) : void
        {
            GameRMI.instance.iTask.endGuide_async(new AMI_ITask_endGuide(), param1);
            return;
        }// end function

        public function cancelTask(param1:int) : void
        {
            GameRMI.instance.iTask.cancelTask_async(new AMI_ITask_cancelTask(), param1);
            return;
        }// end function

        public function digTreasure() : void
        {
            GameRMI.instance.iTask.digTreasure_async(new AMI_ITask_digTreasure());
            return;
        }// end function

        public function explore() : void
        {
            GameRMI.instance.iTask.explore_async(new AMI_ITask_explore(this.submitTaskSucess, this.submitTaskFail));
            return;
        }// end function

        public function quickComplete(param1:int, param2:Boolean = false) : void
        {
            GameRMI.instance.iTask.quickCompleteTask_async(new AMI_ITask_quickCompleteTask(), param1, param2);
            return;
        }// end function

        public function finishDramaStep(param1:int) : void
        {
            GameRMI.instance.iTask.dramaStep_async(new AMI_ITask_dramaStep(), param1);
            return;
        }// end function

        public function shareGuildTask() : void
        {
            TaskProxy.clickShareTime = -1;
            GuildTaskGetWinNew.needClickShare = false;
            GameRMI.instance.iTask.shareGuildTask_async(new AMI_ITask_shareGuildTask(this.shareGuildTaskSuccess));
            return;
        }// end function

        private function shareGuildTaskSuccess(param1:Object) : void
        {
            NetDispatcher.dispatchCmd(ServerCommand.TaskGuildShareSuccess, null);
            return;
        }// end function

        public function guildTaskOneKeyOrange() : void
        {
            TaskProxy.clickShareTime = -1;
            GameRMI.instance.iTask.refreshGuildTaskColor_async(new AMI_ITask_refreshGuildTaskColor());
            return;
        }// end function

        public function guildTaskGetShareList() : void
        {
            GameRMI.instance.iTask.getGuildTaskShareList_async(new AMI_ITask_getGuildTaskShareList());
            return;
        }// end function

        public function askShareGuildTask(param1:SEntityId) : void
        {
            GameRMI.instance.iTask.demandShareGuildTask_async(new AMI_ITask_demandShareGuildTask(), param1);
            return;
        }// end function

        public function getSharedGuildTask(param1:SEntityId, param2:int) : void
        {
            clickShareTime = FrameManager.flashFrame.getTime();
            GameRMI.instance.iTask.getShareGuildTask_async(new AMI_ITask_getShareGuildTask(), param1, param2);
            return;
        }// end function

        public function getMiningAllTaskInfos(param1:int) : void
        {
            GameRMI.instance.iTask.requireRoutineTaskPanelInfo_async(new AMI_ITask_requireRoutineTaskPanelInfo(), param1);
            return;
        }// end function

        public function getMiningRefreshInfos() : void
        {
            GameRMI.instance.iTask.requireRoutineTaskRefreshPanelInfo_async(new AMI_ITask_requireRoutineTaskRefreshPanelInfo());
            return;
        }// end function

        public function helpOtherRrefreshMiningTask(param1:int) : void
        {
            GameRMI.instance.iTask.refreshRoutineTask_async(new AMI_ITask_refreshRoutineTask(), param1);
            return;
        }// end function

        public function miningAskForHelp(param1:int) : void
        {
            GameRMI.instance.iTask.inviteRefreshRoutineTask_async(new AMI_ITask_inviteRefreshRoutineTask(), param1);
            return;
        }// end function

        public function miningRefuseRefreshTask(param1:int) : void
        {
            GameRMI.instance.iTask.rejectRefreshRoutineTask_async(new AMI_ITask_rejectRefreshRoutineTask(), param1);
            return;
        }// end function

        public function endFly() : void
        {
            GameRMI.instance.iTask.endFly_async(new AMI_ITask_endFly());
            return;
        }// end function

        public function getEscortInfoPos() : void
        {
            GameRMI.instance.iTask.getEscortInfo_async(new AMI_ITask_getEscortInfo(this.getEscortPosSuccess));
            return;
        }// end function

        private function getEscortPosSuccess(param1:AMI_ITask_getEscortInfo, param2:int, param3:SPoint) : void
        {
            AIManager.cancelAll();
            AIManager.addMoveToOtherMap(MapFileUtil.mapID, param2, new Point(param3.x, param3.y), 0);
            AIManager.start();
            return;
        }// end function

    }
}
